/*
 * AboutDialog.java Created on Feb 16, 2003 11:05:00 AM
 *
 * Copyright (C) 2003 eRocX Software Group - www.erocx.com
 */
package com.erocx.c24;

import java.awt.Container;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSeparator;

/**
 * <p>Title: AboutDialog</p>
 * <p>Description: the about dialog</p>
 * 
 * @author		<a href="mailto:eroclu@gmail.com">Andy Lu</a>
 * @version   	1.0
 */

public final class AboutDialog extends JDialog {
    private String title = ResourceUtil.getString("about.title");
    private JLabel label, authorLabel, author, emailLabel, email, dateLabel, date, versionLabel;
    private JButton okButton;

    public AboutDialog(JFrame frame) {
        setModal(true);
        setTitle(title);

        doPreliminaryWork();

        Container c = getContentPane();
        c.add(createContentPanel());

        pack();
/*
        addMouseListener(new MouseAdapter() {
            public void mouseClicked(MouseEvent e) {
                //f (e.getButton() == MouseEvent.l)
                AboutDialog.this.dispose();
            }
        });
*/
        setResizable(false);

        setLocationRelativeTo(frame);
    }

    private void doPreliminaryWork() {
        label = new JLabel(ResourceUtil.getString("application.name"));
        authorLabel = new JLabel(ResourceUtil.getString("author"));
        author = new JLabel("Andy Lu");
        emailLabel = new JLabel(ResourceUtil.getString("email"));
        email = new JLabel("eroclu@gmail.com");
        dateLabel = new JLabel(ResourceUtil.getString("date"));
        date = new JLabel("08/15/2003");
        versionLabel = new JLabel("v0.90");

        okButton = new JButton(ResourceUtil.getString("ok.button"));
        okButton.setPreferredSize(new Dimension(75, 23));
        okButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                AboutDialog.this.dispose();
            }
        });
    }

    private JPanel createContentPanel() {
        JPanel content = new JPanel();

        GridBagLayout gbl = new GridBagLayout();
        GridBagConstraints gbc = new GridBagConstraints();

        JPanel image = new JPanel();
        Icon icon = new ImageIcon(ResourceUtil.getImage("about.gif"));
        image.add(new JLabel(icon));

        JSeparator separator = new JSeparator();
        separator.setPreferredSize(new Dimension(280, 2));

        content.setLayout(gbl);

        gbc.anchor = GridBagConstraints.NORTHWEST;
        gbc.gridwidth = 1;
        gbc.gridheight = 4;
        gbc.gridy = 0;
        gbc.gridx = 0;
        content.add(image, gbc);

        gbc.gridheight = 1;
        gbc.gridx = 1;
        gbc.insets = new Insets(5, 5, 0, 0);
        content.add(label, gbc);
        gbc.gridx = 2;
        gbc.insets = new Insets(5, 4, 0, 0);
        content.add(versionLabel, gbc);

        gbc.gridy++;
        gbc.gridx = 1;
        gbc.insets = new Insets(5, 5, 0, 0);
        content.add(authorLabel, gbc);
        gbc.gridx = 2;
        gbc.insets = new Insets(5, 4, 0, 0);
        content.add(author, gbc);

        gbc.gridy++;
        gbc.gridx = 1;
        gbc.insets = new Insets(5, 5, 0, 0);
        content.add(emailLabel, gbc);
        gbc.gridx = 2;
        gbc.insets = new Insets(5, 4, 0, 0);
        content.add(email, gbc);

        gbc.gridy++;
        gbc.gridx = 1;
        gbc.insets = new Insets(5, 5, 0, 0);
        content.add(dateLabel, gbc);
        gbc.gridx = 2;
        gbc.insets = new Insets(5, 4, 0, 0);
        content.add(date, gbc);

        gbc.gridy++;
        gbc.gridx = 0;
        gbc.gridwidth = GridBagConstraints.REMAINDER;
        gbc.insets = new Insets(5, 0, 0, 0);
        content.add(separator, gbc);

        gbc.gridy++;
        gbc.gridx = 0;
        gbc.gridwidth = GridBagConstraints.REMAINDER;
        gbc.anchor = GridBagConstraints.SOUTHEAST;
        gbc.insets = new Insets(8, 0, 6, 8);
        content.add(okButton, gbc);

        return content;
    }

}